package com.pcbly.web.components.taglib;

import java.io.Writer;

import com.opensymphony.xwork2.util.ValueStack;

public class TextField extends Base {
	protected String type;
	protected String size;
	protected String maxLength;
	protected String readonly;

	public String getType() {
		return type;
	}

	public boolean start(Writer writer) {
		boolean result = super.start(writer);
		try {
			StringBuilder sb = new StringBuilder("");
			sb.append("<div class=\"x-form-element\">\r\n");
			sb.append("\t<input ");
			sb.append(" type=\"");
			sb.append(type);
			sb.append("\" ");

			sb.append(" class=\"");
			if (cssClass != null)
				sb.append(cssClass);
			else {
				sb.append("x-form-text x-form-field");
			}
			sb.append("\" ");

			if (cssStyle != null) {
				sb.append(" style=\"");
				sb.append(cssStyle);
				sb.append("\" ");
			}

			if (size != null) {
				sb.append(" size=\"");
				sb.append(size);
				sb.append("\" ");
			}

			if (disabled != null) {
				sb.append(" disabled=\"");
				sb.append(disabled);
				sb.append("\" ");
			}
			if (name != null) {
				sb.append(" name=\"");
				sb.append(name);
				sb.append("\" ");
			}
			if (id != null) {
				sb.append(" id=\"");
				sb.append(id);
				sb.append("\" ");
			}
			if (title != null) {
				sb.append(" title=\"");
				sb.append(title);
				sb.append("\" ");
			}
			if (value != null) {
				sb.append(" value=\"");
				sb.append(value);
				sb.append("\" ");
			}
			if (title != null) {
				sb.append(" title=\"");
				sb.append(title);
				sb.append("\" ");
			}
			if (maxLength != null) {
				sb.append(" maxLength=\"");
				sb.append(maxLength);
				sb.append("\" ");
			}
			if (readonly != null) {
				sb.append(" readonly=\"");
				sb.append(readonly);
				sb.append("\" ");
			}

			sb.append(" onclick=\"javascript:");
			sb.append("this.className='x-form-text x-form-field x-form-click';");
			if (onclick != null) {
				sb.append(onclick);
			}
			sb.append("\" ");

			if (ondblclick != null) {
				sb.append(" ondblclick=\"");
				sb.append(ondblclick);
				sb.append("\" ");
			}
			if (onmousedown != null) {
				sb.append(" onmousedown=\"");
				sb.append(onmousedown);
				sb.append("\" ");
			}
			if (onmouseup != null) {
				sb.append(" onmouseup=\"");
				sb.append(onmouseup);
				sb.append("\" ");
			}
			if (onmouseover != null) {
				sb.append(" onmouseover=\"");
				sb.append(onmouseover);
				sb.append("\" ");
			}
			if (onmousemove != null) {
				sb.append(" onmousemove=\"");
				sb.append(onmousemove);
				sb.append("\" ");
			}

			sb.append(" onmouseout=\"javascript:");
			if (cssClass != null) {
				sb.append("this.className='");
				sb.append(cssClass);
				sb.append("';");
			} else
				sb.append("this.className='x-form-text x-form-field';");
			if (onmouseout != null) {
				sb.append(onmouseout);
			}
			sb.append("\" ");

			sb.append(" onfocus=\"javascript:");
			sb.append("this.className='x-form-text x-form-field x-form-focus';");
			if (onfocus != null) {
				sb.append(onfocus);
			}
			sb.append("\" ");

			if (onblur != null) {
				sb.append(" onblur=\"");
				sb.append(onblur);
				sb.append("\" ");
			}
			if (onkeypress != null) {
				sb.append(" onkeypress=\"");
				sb.append(onkeypress);
				sb.append("\" ");
			}
			if (onkeydown != null) {
				sb.append(" onkeydown=\"");
				sb.append(onkeydown);
				sb.append("\" ");
			}
			if (onkeyup != null) {
				sb.append(" onkeyup=\"");
				sb.append(onkeyup);
				sb.append("\" ");
			}
			if (onselect != null) {
				sb.append(" onselect=\"");
				sb.append(onselect);
				sb.append("\" ");
			}
			if (onchange != null) {
				sb.append(" onchange=\"");
				sb.append(onchange);
				sb.append("\" ");
			}
			sb.append("></input>\r\n");
			sb.append("</div>\r\n");
			sb.append("<div class=\"x-form-clear-left\"/>\r\n");
			writer.write(sb.toString());
		} catch (Exception e) {
			log.error(e.getMessage());
		}
		return result;
	}

	public void setType(String type) {
		this.type = type;
	}

	public TextField(ValueStack stack) {
		super(stack);
		// TODO Auto-generated constructor stub
	}

	public String getSize() {
		return size;
	}

	public void setSize(String size) {
		this.size = size;
	}

	public String getMaxLength() {
		return maxLength;
	}

	public void setMaxLength(String maxLength) {
		this.maxLength = maxLength;
	}

	public String getReadonly() {
		return readonly;
	}

	public void setReadonly(String readonly) {
		this.readonly = readonly;
	}

}
